//
//  ActivityListCell.m
//  ExcellentHome
//
//  Created by 揭婧雯 on 16/9/2.
//  Copyright © 2016年 陈区. All rights reserved.
//

#import "ActivityListCell.h"

#define WIDTH ([UIScreen mainScreen].bounds.size.width)

@interface ActivityListCell ()

@property (nonatomic, strong) UIImageView* linebg;
@property (nonatomic, strong) UILabel *lbName;
@property (nonatomic, strong) UILabel *lbDateToDate;
@property (nonatomic, strong) UILabel *lbNum;
@property (nonatomic, strong) UIImageView * image;

@end

@implementation ActivityListCell

+ (instancetype)cellWithTableView:(UITableView*)tableView
{
    ActivityListCell* cell = [tableView dequeueReusableCellWithIdentifier:kActivityListCellIdentifier];
    
    if (cell == nil) {
        
        cell = [[ActivityListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kActivityListCellIdentifier];
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier
{
    
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    return self;
}

- (void)setFrame:(CGRect)frame
{
    frame.size.width = [UIScreen mainScreen].bounds.size.width;
    [super setFrame:frame];
}

- (void)setupUI
{  
    self.accessoryType = UITableViewCellAccessoryNone;
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    CGRect cellBounds = CGRectMake(10, 79.5, CGRectGetWidth(self.bounds), 0.5);
    self.linebg = [[UIImageView alloc] initWithFrame:cellBounds];
    self.linebg.image = [UIImage imageWithContentsOfFile:SEGPicName(@"common_line610px.png")];
    [self.contentView addSubview:self.linebg];
    
    self.image=[[UIImageView alloc] init];
    self.image.image=[UIImage imageWithContentsOfFile:SEGPicName(@"pic_default_300_300")];
    self.image.contentMode = UIViewContentModeScaleAspectFill;
    [self.image.layer setMasksToBounds:YES];
    [self.contentView addSubview:self.image];
    
    self.lbName = [[UILabel alloc] initWithFrame:CGRectMake(125, 16, 180, 15)];
    self.lbName.font = [UIFont systemFontOfSize:FONT_LIST_AND_DETAIL_SIZE];
    self.lbName.backgroundColor = [UIColor clearColor];
    self.lbName.textColor=kColor_1;
    [self.contentView addSubview:self.lbName];
    
    self.lbDateToDate = [[UILabel alloc] initWithFrame:CGRectMake(125, 50, 170, 13)];
    self.lbDateToDate.font = [UIFont systemFontOfSize:FONT_BRIEF_SIZE];
    self.lbDateToDate.textColor=kColor_1;
    self.lbDateToDate.backgroundColor = [UIColor clearColor];
    self.lbDateToDate.textColor=[UIColor grayColor];
    [self.contentView addSubview:self.lbDateToDate];
    
    self.lbNum = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetWidth(self.bounds)-36, 20, 36, 80)];
    self.lbNum.backgroundColor = [UIColor clearColor];
    self.lbNum.textColor = kColor_T;
    self.lbNum.font = [UIFont systemFontOfSize:FONT_BRIEF_SIZE];
    [self.contentView addSubview:self.lbNum];

}

- (void)setDataSource:(ActivityModel *)dataSource
{
    _dataSource = dataSource;

    self.image.frame=CGRectMake(10, 10, 100, 60);

    [self.image setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",kClientImageRootURL,dataSource.pic1]] placeholderImage:[UIImage imageWithContentsOfFile:SEGPicName(@"pic_default_300_300")] options:SDWebImageLowPriority];

    self.lbName.text = dataSource.name;
    self.lbNum.text=[NSString stringWithFormat:@"%@人",dataSource.activityNum];
    NSDate *beginDate = [SEGUtils dateFromString:dataSource.startDate withFormatString:kTimeFormatStringSec];
    NSDate *endDate = [SEGUtils dateFromString:dataSource.endDate withFormatString:kTimeFormatStringSec];
    NSString *bTime = [SEGUtils stringDateByFormatString:@"yyyy.MM.dd" withDate:beginDate];
    NSString *eTime = [SEGUtils stringDateByFormatString:@"MM.dd" withDate:endDate];
    NSString *time2time = [NSString stringWithFormat:@"%@-%@",bTime,eTime];
    self.lbDateToDate.text = time2time;
}

- (void)setIsLastRow:(BOOL)isLastRow
{
    _isLastRow = isLastRow;
    if (isLastRow) {
        self.linebg.frame=CGRectMake(0, 79.5, CGRectGetWidth(self.bounds), 0.5);
    }else {
        self.linebg.frame=CGRectMake(10, 79.5, CGRectGetWidth(self.bounds), 0.5);
    }
}
@end
